package com.lalala.util;

import java.util.Scanner;

/**
 * 控制台UI的一些常用方法
 */
public class MyUIUtils {

	/**
	 * 制表所需的一连串相同字符
	 * @param charNum 需要打印的字符
	 * @param c 数量
	 * @return c个字符组成的字符串
	 */
	public static String charString (int charNum, char c) {
		char[] charString = new char[charNum];
		for (int i = 0; i < charNum; i++) {
			charString[i] = c;
		}
		return new String(charString);
	}

	/**
	 * 打印标题
	 * @param title 标题
	 */
	public static void printTitle(String title, int charNum, char c) {
		System.out.printf("%s%s%s\n", MyUIUtils.charString(charNum,c), title, MyUIUtils.charString(charNum,c));
	}

	/**
	 * 打印选项
	 * @param options 选项
	 */
	public static void printOption(String... options) {
		if (options.length != 0) {
			StringBuilder optionStr = new StringBuilder();
			for (int i = 1; i <= options.length; i++) {
				optionStr.append(i).append(".").append(options[i - 1]).append(" ");
			}
			System.out.print(optionStr + "0.退出\n请选择: ");
		}
		else
			System.out.print("0.退出\n请选择: ");
	}

	/**
	 * 打印 是否确认
	 */
	public static boolean printSure() {
		System.out.print("请输入[Y:确认,其他:否]：");
		String next = new Scanner(System.in).next();
		return next.equals("Y");
	}

	/**
	 * 打印输入错误<p>sleep(1) 的原因 输入输出流冲突
	 */
	public static void printErr() {
		System.out.println("输入错误！");
		try {
			Thread.sleep(1);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
